package com.gitee.grower.core.ui

import com.gitee.grower.ItemGrowerAPI
import com.gitee.grower.core.kether.toKetherDouble
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.platform.util.isNotAir

abstract class Infer(val item: ItemStack?) {

    val isValid = item != null && item.isNotAir()

    abstract val match: Boolean

    fun takeItem(amount: Int) {
        this.item?.amount = this.item!!.amount - amount
    }

    abstract fun get(player: Player, item: ItemStack) : Double

    class InferFortune(item: ItemStack?) : Infer(item) {

        val curse = ItemGrowerAPI.getFortuneCurse(item)

        override val match: Boolean
            get() = curse != null

        override fun get(player: Player,item: ItemStack) : Double {

            if (!isValid || !match) return 0.0

            return toKetherDouble(player,curse!!.chance,item)
        }
    }

    class InferPerfect(item: ItemStack?) : Infer(item) {

        val curse = ItemGrowerAPI.getPerfectCurse(item)

        override val match: Boolean
            get() = curse != null

        override fun get(player: Player,item: ItemStack) : Double {

            if (!isValid || !match) return 0.0

            return toKetherDouble(player,curse!!.chance,item)
        }
    }
}
